import navBottom from '../common/nav-bottom.vue'
import './notificationCenter.scss';
import XHeader from 'vux/src/components/x-header/index.vue'
import Scroller from 'vux/src/components/scroller/index.vue'
import LoadMore from 'vux/src/components/load-more/index.vue'
import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';

export default {
  name: 'notificationCenter',
  components: {navBottom, XHeader, Scroller, LoadMore },
  data () {
    return {
      userId: '',
      list: [],
      use_pullup: true,
      pageNo: 1,
      pageSize: 5,
      pullup_con: {
        content: ' ',
        pullUpHeight: 60,
        height: 40,
        autoRefresh: false,
        downContent: ' ',
        upContent: ' ',
        loadingContent: ' ',
        clsPrefix: 'xs-plugin-pullup-'
      },
      tipText: '上拉进行加载',
      show_loading: false,
    }
  },
  mounted () {
    this.userId = window.sessionStorage.getItem("userId")
    this.tipText = '正在加载数据，请稍后'
    this.show_loading = true
    this.goEventList()
  },
  methods: {
    onScrollBottom () {
      console.log('上拉加载')
      this.tipText = '正在加载数据，请稍后'
      this.show_loading = true
      this.pageNo++
      this.goEventList()
    },
    goEventList () {
      http.post(CONSTANT.qycMSGSEND, {userId: this.userId, pageNo: this.pageNo, pageSize: this.pageSize}, (res) => {
        console.log(res)
        if (this.pageNo == 1) {
          if (res.code == 200) {
            if (res.obj == '') {
              this.tipText = '暂时没有系统通知'
              this.show_loading = false
              return
            }
            this.list = res.obj
            this.tipText = '上拉进行加载'
            this.show_loading = false
            this.$nextTick(() => {
              this.$refs.scroller.donePullup(function () {
                this.$refs.scroller.reset()
              })
            })
          } else {
            this.tipText = '加载数据失败'
            this.show_loading = false
          }
        } else {
          if (res.code == 200) {
            if (res.obj == '') {
              this.tipText = '没有更多通知了'
              this.show_loading = false
              return
            }
            this.list = this.list.concat(res.obj)
            this.tipText = '上拉进行加载'
            this.show_loading = false
            this.$nextTick(() => {
              this.$refs.scroller.donePullup(function () {
                this.$refs.scroller.reset()
              })
            })
          }
        }

      })
    },
    gonoticeDetails (e) {
      http.post(CONSTANT.qycMSGSEND_READ, {id: e}, (res) => {
        // console.log(res)
      })
      this.$router.push({path: '/noticeDetails', query:{id: e}})
    },
    comeBack () {
      window.history.back()
    }
  }
}
